package com.qbw.app.module.home.holder;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.lib.util.ScreenUtil;
import com.qbw.app.R;
import com.qbw.app.databinding.HomeHolderCurrentVehicleBinding;
import com.qbw.app.model.Vehicle;
import com.qbw.app.model.Weather;
import com.qbw.app.module.vehicle.popwindow.VehicleSelectPopWindow;
import com.qbw.core.base.BaseHolder;

/**
 * @author xiansx
 * @date 2020/10/20
 */
public class HomeCurrentVehicleHolder extends BaseHolder<HomeCurrentVehicleHolder.Data, HomeHolderCurrentVehicleBinding> implements View.OnClickListener {


    public HomeCurrentVehicleHolder(Context context, ViewGroup viewParent, Object listener) {
        super(context, R.layout.home_holder_current_vehicle, viewParent, listener);
    }

    @Override
    public void bindData(int position, Data data) {
        super.bindData(position, data);
        if (mData.getVehicleList() != null) {
            mBinding.setVehicle(mData.getVehicleList().getIndexVehicle());
        }
        if (mData.getWeather() != null) {
            mBinding.setWeather(mData.getWeather().getMain());
        }
        mBinding.llCurrentVehicle.setOnClickListener(this);
        mBinding.executePendingBindings();
    }

    @Override
    public void onClick(View v) {
        int vid = v.getId();
        if (vid == R.id.ll_current_vehicle) {
            if (mData.getVehicleList() == null) {
                return;
            }
            VehicleSelectPopWindow window = new VehicleSelectPopWindow(mContext,
                                                                       mData.getVehicleList());
            window.showAsDropDown(v,
                                  ScreenUtil.dp2px(mContext, 13),
                                  ScreenUtil.dp2px(mContext, 10));
        }
    }

    public static class Data {
        private Vehicle.VehicleList mVehicleList;
        private Weather mWeather;

        public Data(Vehicle.VehicleList vehicleList, Weather weather) {
            mVehicleList = vehicleList;
            mWeather = weather;
        }

        public Vehicle.VehicleList getVehicleList() {
            return mVehicleList;
        }

        public Weather getWeather() {
            return mWeather;
        }

        public void setVehicleList(Vehicle.VehicleList vehicleList) {
            mVehicleList = vehicleList;
        }

        public void setWeather(Weather weather) {
            mWeather = weather;
        }
    }
}
